﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MapEditor
{
    public partial class frmAddTexture : Form
    {
        private string file;
        private Dictionary<int, int> dict;

        public int noText { get; set; }

        public frmAddTexture(string file, Dictionary<int,int> dict)
        {

            InitializeComponent();
            this.file = file;
            this.dict = dict;
        }

        private void frmAddTexture_Load(object sender, EventArgs e)
        {
            pbText.BackgroundImage = Image.FromFile(file);
        }

        private void btnAjout_Click(object sender, EventArgs e)
        {
            int validateInt;
            if (int.TryParse(txtTextNo.Text, out validateInt))
            {
                noText = validateInt;

                if (ValidateKey(noText))
                    this.DialogResult = DialogResult.Yes;
                else
                    MessageBox.Show("Clef déjà utiliser");
            }
            else
                MessageBox.Show("Vous devez Entrer un nombre (ID)");
        }

        private void btnAnnule_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void frmAddTexture_FormClosing(object sender, FormClosingEventArgs e)
        {
            pbText.BackgroundImage.Dispose();
            pbText.Dispose();
            pbText = null;
        }

        private bool ValidateKey(int Keysvalue)
        {
            for (int i = 0; i < dict.Count(); i++)
            {
                try
                {
                    if (dict[i] == Keysvalue)
                        return false;
                }
                catch
                {

                }
            }
            return true;
        }
    }
}
